package com.codechuan.hallo_internal.utils;

import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.codechuan.hallo_internal.MainActivity;
import com.codechuan.hallo_internal.common.Constant;
import com.codechuan.hallo_internal.entity.CityInfo;
import com.codechuan.hallo_internal.entity.SuccessOrder;
import com.codechuan.hallo_internal.entity.SysUserAccountNz;
import com.codechuan.hallo_internal.entity.SysUserConfigNz;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.text.NumberFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.ConnectionPool;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * @Deprecated 自己项目的接口工具类
 */
public class MyProjectHttpUtil {

    /**
     * @Deprecated 卡密登录
     */
    public static JSONObject login(String key, String account) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("key", key);
        hashMap.put("account", account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/loginJt")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            return jsonObject;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * @param CityName 起点位置名称
     * @Deprecated 通过位置获取经纬度等信息接口
     */
    public static CityInfo getCityInfo(String CityName) {
        String url = "https://restapi.amap.com/v3/geocode/geo?address=" + CityName + "&output=JSON&key=0106ec5790369537c595365a3a7777f0";
        String result = null;
        try {
            result = doGet1(url);
        } catch (IOException e) {
            Constant.handler.post(() -> DialogUtil.showDialog(ContextUtil.context, e.getMessage()));
        }
        JSONObject parseObject = JSONObject.parseObject(result);
        JSONArray dataList = JSONObject.parseArray(parseObject.getString("geocodes"));
        if (dataList.isEmpty()) {
            return null;
        }
        JSONObject one = JSONObject.parseObject(dataList.get(0).toString());
        String city = one.getString("city");
        String cityCode = one.getString("citycode");
        String adCode = one.getString("adcode");
        String location = one.getString("location");
        String[] split = location.split(",");
        CityInfo cityInfo = new CityInfo();
        cityInfo.setCity(city);
        cityInfo.setLng(split[0]);
        cityInfo.setLat(split[1]);
        cityInfo.setCityId(cityCode);
        cityInfo.setDistrict(one.getString("district"));
        // 通过城市名称获取邮编和城市区号
        cityInfo.setAdCode(adCode);
        return cityInfo;
    }

    /**
     * @param url 请求地址
     * @Deprecated 同步GET无参请求
     */
    public static String doGet1(String url) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(url)
                .build();
        Response response = okHttpClient.newCall(request).execute();
        return response.body().string();
    }

    /**
     * @param account 账号
     * @return 返回配置文件
     * @Deprecated 获取鸡腿用户配置文件
     */
    public static SysUserConfigNz selectUserConfig(String account) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/getJtUserConfig")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String data = jsonObject.getString("data");
            if (data.equals("null"))
                return null;
            JSONObject jsonData = JSONObject.parseObject(data);
            if (jsonData == null)
                return null;
            // 创建配置文件对象
            SysUserConfigNz sysUserConfigNz = new SysUserConfigNz();
            sysUserConfigNz.setJdMs(jsonData.getString("jdMs"));
            sysUserConfigNz.setPxGz(jsonData.getString("pxGz"));

            sysUserConfigNz.setRzMs(jsonData.getString("rzMs"));
            sysUserConfigNz.setZjDx(jsonData.getString("zjDx"));
            sysUserConfigNz.setYdGs(jsonData.getString("ydGs"));

            sysUserConfigNz.setQdDw(jsonData.getString("qdDw"));
            sysUserConfigNz.setMiniMoney(jsonData.getString("miniMoney"));
            sysUserConfigNz.setMaxMoney(jsonData.getString("maxMoney"));

            sysUserConfigNz.setDtStartDes(jsonData.getString("dtStartDes"));
            sysUserConfigNz.setDtEndDes(jsonData.getString("dtEndDes"));
            sysUserConfigNz.setXcZdJl(jsonData.getString("xcZdJl"));
            sysUserConfigNz.setSld(jsonData.getString("sld"));
            sysUserConfigNz.setPcGzCheck(jsonData.getString("pcGzCheck"));
            sysUserConfigNz.setPcMinPerson(jsonData.getString("pcMinPerson"));
            sysUserConfigNz.setPcMaxPerson(jsonData.getString("pcMaxPerson"));
            sysUserConfigNz.setDxGzCheck(jsonData.getString("dxGzCheck"));
            sysUserConfigNz.setDxMinPerson(jsonData.getString("dxMinPerson"));
            sysUserConfigNz.setDxMaxPerson(jsonData.getString("dxMaxPerson"));
            sysUserConfigNz.setSsGzCheck(jsonData.getString("ssGzCheck"));
            sysUserConfigNz.setSsMinPerson(jsonData.getString("ssMinPerson"));
            sysUserConfigNz.setsMaxPerson(jsonData.getString("ssMaxPerson"));
            sysUserConfigNz.setPcTh(jsonData.getString("pcTh"));
            sysUserConfigNz.setPcCsCheck(jsonData.getString("pcCsCheck"));
            sysUserConfigNz.setPcCsText(jsonData.getString("pcCsText"));
            sysUserConfigNz.setZdCsCheck(jsonData.getString("zdCsCheck"));
            sysUserConfigNz.setZdCsText(jsonData.getString("zdCsText"));
            sysUserConfigNz.setLxQd(jsonData.getString("lxQd"));
            sysUserConfigNz.setAccount(jsonData.getString("account"));
            return sysUserConfigNz;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * @param account
     * @Deprecated 获取用户卡密到期时间
     */
    public static void selectUserExitTime(String key) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("key", key);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/selectUserExitTime")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String string = jsonObject.getString("data");
            Constant.dq_time = string;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static SysUserAccountNz getUserAccount() {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", Constant.account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/getUserAccount")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String string = jsonObject.getString("data");
            JSONObject jsonData = JSONObject.parseObject(string);
            SysUserAccountNz sysUserAccountNz = new SysUserAccountNz();
            sysUserAccountNz.setAccount(jsonData.getString("account"));
            sysUserAccountNz.setAccountStatus(jsonData.getString("accountStatus"));
            sysUserAccountNz.setToken(jsonData.getString("token"));
            sysUserAccountNz.setTicket(jsonData.getString("ticket"));
            sysUserAccountNz.setTokenStatus(jsonData.getString("tokenStatus"));
            return sysUserAccountNz;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static boolean updateAccountToken(String account, String token, String ticket) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", Constant.account);
        hashMap.put("token", token);
        hashMap.put("ticket", ticket);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/updateAccountToken")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String string = jsonObject.getString("data");
            if (string.equals("0"))
                return false;
            return true;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void selectZdCsCityCode(String zdCsText) {
        if (zdCsText.contains("#")) {
            String[] split = zdCsText.split("#");
            for (String name : split) {
                CityInfo cityInfo = MyProjectHttpUtil.getCityInfo(name);
                Constant.cityCodeList.add(cityInfo.getCityId());
            }
        } else {
            CityInfo cityInfo = MyProjectHttpUtil.getCityInfo(zdCsText);
            Constant.cityCodeList.add(cityInfo.getCityId());
        }
    }

    public static void updateAccountTokenStatus() {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", Constant.account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/updateAccountTokenStatus")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static boolean saveAccountConfig(SysUserConfigNz sysUserConfigNz) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("data", JSONObject.toJSONString(sysUserConfigNz));
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/saveAccountConfig")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String string = jsonObject.getString("data");
            if (string.equals("0"))
                return false;
            return true;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static JSONObject getUserOrderList() {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", Constant.account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/getUserOrderList")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            return JSONObject.parseObject(decrypt);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static boolean deleteOrderInfo() {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", Constant.account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/deleteOrderInfo")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String string = jsonObject.getString("data");
            if (string.equals("0"))
                return false;
            return true;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * @param successOrder
     * @Deprecated 新增用户订单
     */
    public static void addUserOrder(SuccessOrder successOrder) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("data", JSONObject.toJSONString(successOrder));
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/addUserOrder")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String noBind(String keyNumber) {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("keyNumber", keyNumber);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/jt/jtNoBind")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = EncryptionUtil.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            return jsonObject.getString("message");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public static JSONObject fuck() {
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("account", Constant.account);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("http://" + Constant.HOST_ADDRESS + ":81/hallo-api/bl/fuck")
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = Demo.decrypt(response.body().string());
            JSONObject data = JSONObject.parseObject(decrypt);
            JSONObject object = JSONObject.parseObject(data.getString("data"));
            return object;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String txm(String ticket, String token, String reqId, String proxy, JSONObject fuck, String challenge, String captchaId, String sid) {

        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("ticket", ticket);
        hashMap.put("token", token);
        hashMap.put("reqId", reqId);
        hashMap.put("SerUrl", "http://127.0.0.1:2000/SlideApi/JySlide");
        hashMap.put("proxy", proxy);
        hashMap.put("challenge", challenge);
        hashMap.put("captchaId", captchaId);
        hashMap.put("sid", sid);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url(fuck.getString("address"))
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            String string = response.body().string();
            if (string.equals("true")) {
                return "处理图形验证成功";
            } else {
                return "处理图形验证失败";
            }
        } catch (Exception e) {
            System.out.println("1");
        }
        System.out.println("处理图形验证失败");
        return "处理图形验证失败";
    }

    public static String txm2(String ticket, String token, String reqId, String proxy, JSONObject fuck) {

        Constant.executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                Constant.isTxm = false;
            }
        });
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("ticket", ticket);
        hashMap.put("token", token);
        hashMap.put("reqId", reqId);
        hashMap.put("SerUrl", "http://127.0.0.1:2000/SlideApi/JySlide");
        hashMap.put("ipAddress", proxy);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(hashMap));
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url(fuck.getString("address2"))
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            String string = response.body().string();
            if (string.equals("true")) {
                return "处理图形验证成功";
            } else {
                return "处理图形验证失败";
            }
        } catch (Exception e) {
            System.out.println("1");
        }
        System.out.println("处理图形验证失败");
        return "处理图形验证失败";
    }


    /**
     * @param data 返回的99数据
     * @return 返回challenge
     * @Deprecated 初始化
     */
    public static HashMap<String, String> initSlider(String data, String token, String ticket, String sid) {
        System.out.println("初始化的sid是:" + sid);
        OkHttpClient client = new OkHttpClient();
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("capToken", token);
        hashMap.put("language", "zho");
        hashMap.put("reqId", data);
        hashMap.put("sid", sid);
        hashMap.put("action", "risk.captcha.init");
        hashMap.put("systemCode", "64");
        hashMap.put("version", "6.73.0");
        hashMap.put("token", token);
        hashMap.put("clientId", "");
        hashMap.put("ticket", ticket);

        String encrypt = null;
        try {

            encrypt = Demo.encrypt(JSONObject.toJSONString(hashMap));
        } catch (Exception e) {
            e.printStackTrace();
        }
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(mediaType, encrypt);
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("https://marketingapi.hellobike.com/api")
                .post(body)
                .addHeader("Host", "api.hellobike.com")
                .addHeader("sid", sid)
                .addHeader("user-agent", "")
                .addHeader("inner_action", "risk.captcha.init")
                .addHeader("systemcode", "64")
                .addHeader("chaos", "true")
                .addHeader("content-type", "application/json; charset=UTF-8")
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = Demo.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            String string = jsonObject.getString("data");
            JSONObject dataJson = JSONObject.parseObject(string);
            if (dataJson == null)
                return null;
            String challenge = dataJson.getString("challenge");
            String captchaId = dataJson.getString("captchaId");
            HashMap<String, String> resutMap = new HashMap<>();
            resutMap.put("challenge", challenge);
            resutMap.put("captchaId", captchaId);
            return resutMap;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static String callBack(HashMap<String, String> dataMap, String sid) {
        System.out.println("回调的sid是:" + sid);
        OkHttpClient client = new OkHttpClient();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("capToken", dataMap.get("capToken"));
        hashMap.put("captchaOutput", dataMap.get("captcha_output"));
        hashMap.put("challenge", dataMap.get("challenge"));
        hashMap.put("genTime", dataMap.get("gen_time"));
        hashMap.put("lotNumber", dataMap.get("lot_number"));
        hashMap.put("passToken", dataMap.get("pass_token"));
        hashMap.put("reqId", dataMap.get("reqId"));
        hashMap.put("riskType", "");
        hashMap.put("sid", sid);
        hashMap.put("systemCode", "62");
        hashMap.put("action", "risk.captcha.check");
        hashMap.put("version", "6.73.0");
        hashMap.put("token", dataMap.get("capToken"));
        hashMap.put("clientId", "");
        hashMap.put("ticket", dataMap.get("ticket"));
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        String encrypt;
        try {
            encrypt = Demo.encrypt(JSONObject.toJSONString(hashMap));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        RequestBody body = RequestBody.create(mediaType, encrypt);
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("https://marketingapi.hellobike.com/api")
                .post(body)
                .addHeader("Host", "api.hellobike.com")
                .addHeader("sid", sid)
                .addHeader("user-agent", "")
                .addHeader("inner_action", "risk.captcha.check")
                .addHeader("systemcode", "62")
                .addHeader("chaos", "true")
                .addHeader("content-type", "application/json; charset=UTF-8")
                .addHeader("accept-encoding", "accept-encoding")
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            String decrypt = Demo.decrypt(response.body().string());
            JSONObject jsonObject = JSONObject.parseObject(decrypt);
            System.out.println("jsonObject = " + jsonObject);
            String msg = jsonObject.getString("msg");
            String success = jsonObject.getString("data");
            JSONObject successData = JSONObject.parseObject(success);
            System.out.println(Constant.format.format(new Date()) + ":" + jsonObject);
            if (msg.equals("ok") && successData.getString("success").equals("1")) {
                System.out.println("处理图形验证成功");
                return "处理图形验证成功";
            }
            System.out.println("处理图形验证失败");
            return "处理图形验证失败";
        } catch (Exception e) {
        }
        System.out.println("处理图形验证失败");
        return "处理图形验证失败";
    }


    public static HashMap<String, String> getCodePostBL(String id, String proxy, JSONObject json) {

        OkHttpClient client = new OkHttpClient();

        // MediaType 对应 Content-Type
        MediaType mediaType = MediaType.parse("multipart/form-data");

        // 创建 RequestBody
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("captcha_id", id)
                .addFormDataPart("proxy", proxy)
                // 可以添加更多的键值对
                .build();
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url(json.getString("server1"))
                .post(body)
                .build();
        // 发送请求并获取响应
        Response response = null;
        try {
            response = client.newCall(request).execute();
            // 解密原文
            JSONObject jsonObject = JSONObject.parseObject(response.body().string());
            String string = jsonObject.getString("data");
            JSONObject jsonObject1 = JSONObject.parseObject(string);

            JSONObject dataJson = jsonObject1.getJSONObject("code");
            String lotNumber = dataJson.getString("lot_number");
            String passToken = dataJson.getString("pass_token");
            String genTime = dataJson.getString("gen_time");
            String captchaOutput = dataJson.getString("captcha_output");
            // 封准需要的数据
            HashMap<String, String> codeData = new HashMap<>();
            codeData.put("captcha_output", captchaOutput);
            codeData.put("gen_time", genTime);
            codeData.put("lot_number", lotNumber);
            codeData.put("pass_token", passToken);
            return codeData;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private static String configureTasks2() {
        String url = "http://api1.ydaili.cn/tools/MeasureApi.ashx?action=EAPI&secret=D5C9B1FA57EF5B3897BD51EEC9F440707F10281F1653D0C80178F447029E5526B57E95DB97FBA866&number=1&orderId=SH20241029181517960&format=txt";
        String result = null;
        try {
            result = MyProjectHttpUtil.doGet1(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    public static void demo(String encrypt,String token,String ticket,JSONObject fuck) {
        Constant.executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                Constant.isTxm = false;
            }
        });

        String proxy = configureTasks2();
        if (proxy == null)
            return;
        proxy = proxy.replaceAll("\\r\\n","");
        // 使用代理ip请求 避免踢码
        String[] split = proxy.split(":");
        Proxy proxys = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(split[0], Integer.valueOf(split[1])));

        OkHttpClient client = new OkHttpClient().newBuilder()
                .followRedirects(false)
                .followSslRedirects(false)
                .connectTimeout(5, TimeUnit.SECONDS)
                .readTimeout(5, TimeUnit.SECONDS)
                .proxy(proxys)
                .connectionPool(new ConnectionPool(5, 1, TimeUnit.SECONDS))
                .build();

        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, encrypt);
        // 创建请求对象，并添加自定义的请求头
        Request request = new Request.Builder()
                .url("https://taxiapi.hellobike.com/api")
                .post(body)
                .addHeader("Host", "taxiapi.hellobike.com")
                .addHeader("Connection", "keep-alive")
                .addHeader("content-type", "application/json; charset=UTF-8")
                .addHeader("user-agent", "Mozilla/5.0 (Linux; Android 13; 23049RAD8C Build/TKQ1.221114.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/127.0.6533.103 Mobile Safari/537.36")
                .addHeader("inner_action", "hitch.driver.journeyList")
                .addHeader("systemcode", "62")
                .addHeader("chaos", "true")
                .build();

        String finalProxy = proxy;
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }
            @Override
            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                response = client.newCall(request).execute();
                assert response.body() != null;
                String decrypt = null;
                try {
                    decrypt = Demo.decrypt(response.body().string());
                    JSONObject jsonObjectOne = JSONObject.parseObject(decrypt);
                    System.out.println(jsonObjectOne);
                    String status = jsonObjectOne.getString("code");
                    if (status.equals("99")) {
                        JSONObject jsonObject = JSONObject.parseObject(jsonObjectOne.toString());
                        String data = jsonObject.getString("data");
                        MyProjectHttpUtil.txm2(ticket,token,data, finalProxy,fuck);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

            }
        });
    }


}
